package the.one.base.adapter;

import android.widget.TextView;

import org.jetbrains.annotations.NotNull;

import the.one.base.Interface.IPopupItem;
import the.one.base.R;

/**
 * @author The one
 * @date 2018/7/31 0031
 * @describe TODO
 * @email 625805189@qq.com
 * @remark
 */
public class ListPopupAdapter<T extends IPopupItem> extends TheBaseQuickAdapter<T> {

    private int mPosition = -1;

    public ListPopupAdapter() {
        super(R.layout.simple_list_item);
    }

    public void setSelect(int position){
        mPosition = position;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(@NotNull TheBaseViewHolder holder, T data) {
        if(data.isHaveIcon()){
            holder.getImageView(R.id.icon).setImageResource(data.getIconRes());
        }
        TextView textView = holder.getView(R.id.text);
        textView.setText(data.getTitle());
        textView.setGravity(data.getTitleGravity());
        holder.setVisible(R.id.iv_select,holder.getAdapterPosition() == mPosition);
    }

}
